<script setup>

import {onMounted, ref} from "vue";
import {AnnounceJob, GetEnterprise} from "@/utils/api/enterprise.js";
import {useUserLoginStore} from "@/stores/AccountLogin.js";
import {ElMessage, ElNotification} from "element-plus";

const eno = useUserLoginStore().getAccount;
const jobInfo = ref('');
const enterpriseInfo = ref({
  enterpriseName: '',
  registerNumber: '',
  legalRepresentative: '',
});

const getEnterpriseInfo = ()=>{

  GetEnterprise(eno)
      .then(result => {
        if (result.code === 1) {
          enterpriseInfo.value = result.data;
        }else {
          ElMessage({
            message:"服务器错误",
            type:'error',
          })
        }
      }).catch(error => console.error(error.toString()))
}

const announce = () => {
  if(jobInfo.value === ''){
    ElMessage({
      message:'请输入招聘信息',
      type:'error',
    })
    return;
  }
  AnnounceJob(eno, jobInfo.value)
      .then(result => {
        if (result.code === 1) {
          ElNotification({
            title: '发布成功',
            type: 'success',
            duration: 2000,
          });
          jobInfo.value = '';
        }else {
          ElMessage({
            message: "发布失败，请重试",
            type:'error',
          })
        }
      })
}

onMounted(() => {
  getEnterpriseInfo();
})
</script>

<template>
  <div class="main">
    <el-descriptions direction="vertical" border>
      <el-descriptions-item label="企业编号">
        {{ eno }}
      </el-descriptions-item>
      <el-descriptions-item label="注册编号">
        {{ enterpriseInfo.registerNumber }}
      </el-descriptions-item>
      <el-descriptions-item label="企业名称">
        {{ enterpriseInfo.enterpriseName }}
      </el-descriptions-item>
      <el-descriptions-item label="招聘信息">
        <el-input type="textarea" :rows="14" v-model="jobInfo"/>
      </el-descriptions-item>
    </el-descriptions>
    <div class="operation">
      <el-button type="primary" @click="jobInfo = ''">重 置</el-button>
      <el-button type="success" @click="announce">发 布</el-button>
    </div>
  </div>
</template>

<style scoped>
.main {
  min-width: 1100px;
  padding-right: 50px;
}

.el-button {
  margin-left: 100px;
  margin-top: 20px;
}
</style>